<template>

  <div>
    <el-card class="box-card">
      <el-form ref="line" :model="queryVO" label-width="150px" :inline="true">
        <el-form-item label="线路编号:" prop="lineNumber">
          <el-input type="text" placeholder="请输入线路编号" v-model="queryVO.lineNumber"></el-input>
        </el-form-item>
        <el-form-item label="线路名称:" prop="name">
          <el-input type="text" placeholder="请输入线路名称" v-model="queryVO.name"></el-input>
        </el-form-item>
        <el-form-item label="线路类型:" prop="transportLineTypeId">
          <el-select v-model="queryVO.transportLineTypeId" clearable placeholder="请选择">
            <el-option
              v-for="item in lineTypeData"
              :label="item.name"
              :value="item.id"
              :key="item.name">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="sousuo()" icon="el-icon-search" type="primary">查询</el-button>
          <el-button @click="reset('line')" icon="el-icon-refresh">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <el-divider></el-divider>

    <el-card class="box-card">
      <el-button @click="openAddLine()" type="info" icon="el-icon-edit">新增线路</el-button>
      <el-table v-loading="loading" :data="tableData" style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="scop">
            <el-card>
              <el-table :data=scop.row.tripsList style="width: 100%">
                <el-table-column prop="trips.name" label="车次名称">

                </el-table-column>
                <el-table-column prop="trips.period" label="发车频次">
                  <template slot-scope="scop">
                    <span>{{ scop.row.trips.departureTime }}/</span>
                    <span v-if="scop.row.trips.period == '1'">天</span>
                    <span v-if="scop.row.trips.period == '2'">周</span>
                    <span v-if="scop.row.trips.period == '3'">月</span>
                  </template>
                </el-table-column>
                <el-table-column prop="" label="车辆司机安排">
                  <template slot-scope="scop">
                    <span v-for="item in scop.row.truckDriver">
                      {{ item.truck }}--{{ item.driver }}
                    </span>
                  </template>
                </el-table-column>
                <el-table-column
                  fixed="right"
                  label="操作">
                  <template slot-scope="scope">
                    <el-button type="text" size="medium " @click="openUpdTrips(scop.row,scope.row)">编辑车次</el-button>
                    <el-button style="color: red" type="text" size="medium" @click="delTrips(scope.row)">删除车次
                    </el-button>
                    <el-button type="text" size="medium " @click="openAddTruck(scop.row,scope.row)">安排车辆</el-button>
                    <el-button type="text" size="medium " @click="openAddDriver(scop.row,scope.row)">安排司机</el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-card>
          </template>
        </el-table-column>
        <el-table-column
          width="80"
          label="序号">
          <template slot-scope="scop">
            <!--            queryVo.pageNum 当前页
                        queryVo.pageSize 页大小-->
            {{ scop.$index + (pagenum - 1) * pagesize + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="lineNumber" label="线路编号">

        </el-table-column>
        <el-table-column prop="name" label="线路名称">

        </el-table-column>
        <el-table-column prop="tname" label="线路类型">

        </el-table-column>
        <el-table-column prop="startAgencyName" label="起始地机构" width="200">

        </el-table-column>
        <el-table-column prop="endAgencyName" label="目的地机构" width="200">

        </el-table-column>
        <el-table-column prop="distance" label="距离(千米)">

        </el-table-column>
        <el-table-column prop="cost" label="平均成本(元)">

        </el-table-column>
        <el-table-column prop="estimatedTime" label="预计时间(分钟)">

        </el-table-column>
        <el-table-column label="线路地图">
          <template slot-scope="scope">
            <el-button type="text" size="medium " icon="el-icon-location-information" @click="openMap(scope.row)">地图
            </el-button>
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          width="200">
          <template slot-scope="scope">
            <el-button type="text" size="medium " @click="openUpdLine(scope.row)">修改</el-button>
            <el-button style="color: red" type="text" size="medium" @click="delLine(scope.row)">删除</el-button>
            <el-button type="text" size="medium " @click="openaddLine(scope.row)">增加车次</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div style="text-align: center">
        <br>
        <el-pagination
          @size-change="setSize"
          @current-change="setPage"
          :current-page="pagenum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pagesum">
        </el-pagination>
      </div>
    </el-card>


    <el-dialog
      title="添加线路"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose">
      <div>
        <el-form ref="addLineData" :model="addLineData" label-width="120px">
          <el-form-item label="* 线路编号:" prop="lineNumber">
            <el-input type="text" placeholder="请输入线路编号" v-model="addLineData.lineNumber"></el-input>
          </el-form-item>
          <el-form-item label="* 线路名称:" prop="name">
            <el-input type="text" placeholder="请输入线路名称" v-model="addLineData.name"></el-input>
          </el-form-item>
          <el-form-item label="* 线路类型:" prop="transportLineTypeId">
            <el-select v-model="addLineData.transportLineTypeId" clearable placeholder="请选择">
              <el-option
                v-for="item in lineTypeData"
                :label="item.name"
                :value="item.id"
                :key="item.name">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="起始地机构:" prop="startAgencyId">
            <el-select v-model="addLineData.startAgencyId" placeholder="请选择起始地机构" ref="selectReport"
                       class="jigouselect">
              <el-option :value="addLineData.startAgencyId" :label="inupDictDataSelect" style="height: auto;">
                <el-tree
                  :data="list"
                  :props="defaultProps"
                  :render-after-expand="true"
                  :expand-on-click-node="false"
                  @node-click="inupHandleNodeClick">
                </el-tree>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="目的地机构:" prop="endAgencyId">
            <el-select v-model="addLineData.endAgencyId" placeholder="请选择目的地机构" class="jigouselect">
              <el-option :value="addLineData.endAgencyId" :label="inupDictDataSelect1" style="height: auto;">
                <el-tree
                  :data="list"
                  :props="defaultProps"
                  :render-after-expand="true"
                  :expand-on-click-node="false"
                  @node-click="inupHandleNodeClick1">
                </el-tree>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="* 距离:" prop="distance">
            <el-input type="text" placeholder="请输入距离" v-model="addLineData.distance">
              <template slot="append">千米</template>
            </el-input>
          </el-form-item>
          <el-form-item label="* 成本:" prop="cost">
            <el-input type="text" placeholder="请输入成本" v-model="addLineData.cost">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="* 预计时间:" prop="estimatedTime">
            <el-input type="text" placeholder="请输入预计时间" v-model="addLineData.estimatedTime">
              <template slot="append">分钟</template>
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="danger" @click="addLine()">添 加</el-button>
      </span>
    </el-dialog>


    <el-dialog
      title="修改线路"
      :visible.sync="dialogVisible1"
      width="30%"
      :before-close="handleClose1">
      <div>
        <el-form ref="addLineData" :model="updLineData" label-width="120px">
          <el-form-item label="* 线路编号:" prop="lineNumber">
            <el-input type="text" placeholder="请输入线路编号" v-model="updLineData.lineNumber"></el-input>
          </el-form-item>
          <el-form-item label="* 线路名称:" prop="name">
            <el-input type="text" placeholder="请输入线路名称" v-model="updLineData.name"></el-input>
          </el-form-item>
          <el-form-item label="* 线路类型:" prop="transportLineTypeId">
            <el-select v-model="updLineData.transportLineTypeId" clearable placeholder="请选择">
              <el-option
                v-for="item in lineTypeData"
                :label="item.name"
                :value="item.id"
                :key="item.name">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="起始地机构:" prop="startAgencyId">
            <el-select v-model="updLineData.startAgencyId" placeholder="请选择起始地机构" ref="selectReport"
                       class="jigouselect">
              <el-option :value="updLineData.startAgencyId" :label="inupDictDataSelect2" style="height: auto;">
                <el-tree
                  :data="list"
                  :props="defaultProps"
                  :render-after-expand="true"
                  :expand-on-click-node="false"
                  @node-click="inupHandleNodeClick2">
                </el-tree>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="目的地机构:" prop="endAgencyId">
            <el-select v-model="updLineData.endAgencyId" placeholder="请选择目的地机构" class="jigouselect">
              <el-option :value="updLineData.endAgencyId" :label="inupDictDataSelect3" style="height: auto;">
                <el-tree
                  :data="list"
                  :props="defaultProps"
                  :render-after-expand="true"
                  :expand-on-click-node="false"
                  @node-click="inupHandleNodeClick3">
                </el-tree>
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="* 距离:" prop="distance">
            <el-input type="text" placeholder="请输入距离" v-model="updLineData.distance">
              <template slot="append">千米</template>
            </el-input>
          </el-form-item>
          <el-form-item label="* 成本:" prop="cost">
            <el-input type="text" placeholder="请输入成本" v-model="updLineData.cost">
              <template slot="append">元</template>
            </el-input>
          </el-form-item>
          <el-form-item label="* 预计时间:" prop="estimatedTime">
            <el-input type="text" placeholder="请输入预计时间" v-model="updLineData.estimatedTime">
              <template slot="append">分钟</template>
            </el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible1 = false">取 消</el-button>
        <el-button type="danger" @click="updLine()">修 改</el-button>
      </span>
    </el-dialog>


    <el-dialog
      :title="map"
      :visible.sync="dialogVisible2"
      :close-on-click-modal="modal"
    >
      <baidu-map
        class="map"
        :center="startMap"
        :zoom="15"
        :scroll-wheel-zoom="true">
        <bm-navigation anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-navigation>
        <bm-driving
          :start="startMap"
          :end="stopMap"
          :panel="false"
          :autoViewport="true">
        </bm-driving>
      </baidu-map>
    </el-dialog>


    <el-dialog
      title="增加车次"
      :visible.sync="adddialogVisible"
      width="30%"
      :before-close="addhandleClose">
      <div>
        <el-form ref="addLineData" :model="addTripsData" label-width="120px" :inline="true">
          <el-form-item label="线路名称:">
            <el-input type="text" disabled placeholder="请输入线路名称" v-model="xianluname"></el-input>
          </el-form-item>
          <el-form-item label="* 车次名称:" prop="name">
            <el-input type="text" placeholder="请输入车次名称" v-model="addTripsData.name"></el-input>
          </el-form-item>
          <el-form-item label="* 发车时间:" prop="departureTime">
            <el-select v-model="addTripsData.departureTime" clearable placeholder="选择发车时间" style="width: 130px">
              <el-option value="8:00" label="8:00">
              </el-option>
              <el-option value="12:00" label="12:00">
              </el-option>
              <el-option value="14:00" label="14:00">
              </el-option>
              <el-option value="16:00" label="16:00">
              </el-option>
              <el-option value="18:00" label="18:00">
              </el-option>
              <el-option value="20:00" label="20:00">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="period">
            <el-select v-model="addTripsData.period" clearable placeholder="选择周期" style="width: 130px">
              <el-option value=1 label="天">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="adddialogVisible = false">取 消</el-button>
        <el-button type="danger" @click="addtrips()">添 加</el-button>
      </span>
    </el-dialog>


    <el-dialog
      title="修改车次"
      :visible.sync="updTripsdialogVisible"
      width="30%"
      :before-close="UpdTripshandleClose">
      <div>
        <el-form ref="updTripsData" :model="updTripsData" label-width="120px" :inline="true">
          <el-form-item label="线路名称:">
            <el-input type="text" disabled placeholder="请输入线路名称" v-model="xianluname"></el-input>
          </el-form-item>
          <el-form-item label="* 车次名称:" prop="name">
            <el-input type="text" placeholder="请输入车次名称" v-model="updTripsData.name"></el-input>
          </el-form-item>
          <el-form-item label="* 发车时间:" prop="departureTime">
            <el-select v-model="updTripsData.departureTime" clearable placeholder="选择发车时间" style="width: 130px">
              <el-option value="8:00" label="8:00">
              </el-option>
              <el-option value="12:00" label="12:00">
              </el-option>
              <el-option value="14:00" label="14:00">
              </el-option>
              <el-option value="16:00" label="16:00">
              </el-option>
              <el-option value="18:00" label="18:00">
              </el-option>
              <el-option value="20:00" label="20:00">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="period">
            <el-select v-model="updTripsData.period" clearable placeholder="选择周期" style="width: 130px">
              <el-option value="1" label="天">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="updTripsdialogVisible = false">取 消</el-button>
        <el-button type="danger" @click="updTrips()">修 改</el-button>
      </span>
    </el-dialog>


    <el-dialog
      title="新增车辆"
      :visible.sync="addTruckdialogVisible"
      width="30%"
      :before-close="addTruckhandleClose">
      <div>
        <el-form ref="addTruckData" :model="addTruckData" label-width="120px" :inline="true">
          <el-form-item label="线路名称:">
            <el-input type="text" disabled v-model="zhanshiAddTruck.xianluname"></el-input>
          </el-form-item>
          <el-form-item label="车次名称:">
            <el-input type="text" disabled v-model="zhanshiAddTruck.name"></el-input>
          </el-form-item>
          <el-form-item label="发车时间:">
            <el-input type="text" disabled v-model="zhanshiAddTruck.departureTime"></el-input>
          </el-form-item>
          <el-form-item label="车辆安排:">
            <el-select v-model="addTruckData" placeholder="请选择车辆">
              <el-option :value="addTruckData.truckId" :label="addTruckData.truckName" style="height: auto;">
                <el-tree
                  :data="fleetTruck"
                  :props="defaultProps2"
                  accordion
                  :render-after-expand="false"
                  :expand-on-click-node="true"
                  @node-click="handleNodeClick2">
                </el-tree>
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="danger" @click="addTruck()">确 认</el-button>
        <el-button @click="addTruckdialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>

    <!--     -&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;&#45;-->

    <el-dialog
      title="新增车辆"
      :visible.sync="addDriverdialogVisible"
      width="30%"
      :before-close="addDriverhandleClose">
      <div>
        <el-form ref="zhanshiAddDriver" :model="zhanshiAddDriver" label-width="120px" :inline="true">
          <el-form-item label="线路名称:">
            <el-input type="text" disabled v-model="zhanshiAddDriver.xianluname"></el-input>
          </el-form-item>
          <el-form-item label="车次名称:">
            <el-input type="text" disabled v-model="zhanshiAddDriver.tripsname"></el-input>
          </el-form-item>
          <el-form-item label="发车时间:">
            <el-input type="text" disabled v-model="zhanshiAddDriver.fachetime"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDriverdialogVisible = false">取 消</el-button>
      </span>

      <h3>车辆司机安排</h3>
      <el-table v-loading="loading1" :data="tripsTruckDriverData" style="width: 100%">
        <el-table-column prop="truckName" label="车辆">

        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="medium" @click="open(scope.row)">司机</el-button>
            <el-button @click="delTruck(scope.row)">×</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>


    <el-dialog
      title="新增车辆"
      :visible.sync="addDriverdialogVisible2"
      width="30%"
      :before-close="addDriverhandleClose2">
      <h3>车辆司机安排</h3>
      <el-select v-model="updTruckDriver.driverId" placeholder="请选择司机">
        <el-option :value="updTruckDriver.driverId" :label="updTruckDriver.driverName" style="height: auto;">
          <el-tree
            :data="fleetDriver"
            :props="defaultProps3"
            accordion
            :render-after-expand="false"
            :expand-on-click-node="true"
            @node-click="handleNodeClick3">
          </el-tree>
        </el-option>
      </el-select>
      <br>
      <br>
      <el-button @click="addDriverdialogVisible2 = false">取 消</el-button>
      <el-button type="danger" @click="updDriver()">修 改</el-button>
    </el-dialog>
  </div>
</template>
<script>
import method from '../../../api/logisticsmanagement/transitcenter/lineManagement'
import organizationAPI from "../../../api/rightsmanagement/organizationmanagement/organization";


export default {
  name: "lineManagement",
  data() {
    return {
      //  当前页
      pagenum: 1,
      //  一页显示几条数据
      pagesize: 5,
      //  总页数
      pagesum: 0,
      //  搜索条件
      queryVO: {
        lineNumber: "",//  线路编号
        name: "",//  线路名称
        transportLineTypeId: ""//  线路类型ID
      },
      //  所有线路类型数据
      lineTypeData: {},
      //  表格数据加载状态
      loading: false,
      //  全部数据
      tableData: [],
      //  添加线路对话框的开启状态
      dialogVisible: false,
      //  添加线路的数据
      addLineData: {},
      list: [], // 树数据
      defaultProps: { // 树规则
        children: 'orgTreeDtoList',
        label: 'name'
      },
      //  添加起始地机构显示值
      inupDictDataSelect: null,
      //  添加目的地机构显示值
      inupDictDataSelect1: null,
      //  修改起始地机构显示值
      inupDictDataSelect2: null,
      //  修改目的地机构显示值
      inupDictDataSelect3: null,
      //  线路修改对话框的状态
      dialogVisible1: false,
      //  修改线路数据
      updLineData: {},
      //  地图开启状态
      dialogVisible2: false,
      //  地图对话框是否开启点击外部关闭对话框
      modal: false,
      //  地图对话框标题
      map: "",
      startMap: {}, // 保存起点数据
      stopMap: {}, // 保存终点数据
      adddialogVisible: false,//  添加车次的对话框状态
      addTripsData: {},//  添加车次的数据
      xianluname: {},//  车次里的线路名称
      addTransportLineId: "",//  时线路ID
      updTripsdialogVisible: false, //  修改车次模态框的开启状态
      updTripsData: {},//  修改车次的数据
      addTruckdialogVisible: false,//  给车次添车辆的对话框状态
      addTruckData: {
        truckName: "",
        truckId: ""
      },//  给车次添加车辆的数据
      zhanshiAddTruck: {//  给车次添加车辆的时的展示数据
        xianluname: "",
        name: "",
        departureTime: ""
      },
      fleetTruck: [],//  所有车队及车队下的车辆数据
      defaultProps2: {
        children: 'list',
        label: 'name'
      },
      truckAll: [],//  所有未使用车辆数据
      tripsId: "",
      // -------------------------------------------------------
      addDriverdialogVisible: false,//  给车次新增司机的对话框
      zhanshiAddDriver: {//  给车次添加司机时的展示数据
        xianluname: "",//  线路名称
        tripsname: "",//  车次名称
        fachetime: ""//  发车时间
      },
      tripsTruckDriverData: [],//  车次车辆司机数据
      loading1: false, //  安排司机table的加载状态
      fleetDriver: [],//  所有车队及车队下的车辆数据
      defaultProps3: {
        children: 'list',
        label: 'name'
      },
      updTruckDriver: {//  给车辆绑定司机
        driverId: "",
        driverName: ""
      },
      addDriverdialogVisible2: false,
      dangqiantruck: "",
      driverTripsID: "",
    }
  },
  methods: {
    //  删除车辆
    delTruck(val) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.addDriverdialogVisible = false
        method.delTripsTruck(val.truckId).then(({data}) => {
          if (data.code == 200) {
            this.$notify({
              title: '成功',
              message: '车辆删除成功!',
              type: 'success'
            })
            this.pageLine()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //  确定修改车辆司机
    updDriver() {
      let obj = {
        truckId: this.dangqiantruck,
        driverId: this.updTruckDriver.driverId,
        tripsId: this.driverTripsID
      }
      this.addDriverdialogVisible2 = false
      method.instripsdriver(obj).then(({data}) => {
        if (data.code == 200) {
          this.$notify({
            title: '成功',
            message: '车辆司机修改成功!',
            type: 'success'
          });
          this.pageLine();
        }
      })
    },
    open(scope) {
      this.findFleetDriver()
      this.dangqiantruck = scope.truckId
      this.updTruckDriver = {
        driverId: scope.driverId,
        driverName: scope.driverName
      }
      this.addDriverdialogVisible2 = true
    },
    addDriverhandleClose2(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {
        });
    },
    //  车队司机树
    fleetDriverM(data) {
      for (let i = 0; i < data.length; i++) {
        this.$set(data[i], 'name', data[i].pdFleet.name)
        if (data[i].list.length > 0) {
          for (let v = 0; v < data[i].list.length; v++) {
            this.$set(data[i].list[v], 'name', data[i].list[v].driverName)
          }
        }
      }
    },
    //  查询树状车队司机数据
    findFleetDriver() {
      method.findFleetDriver().then(({data}) => {
        if (data.code == 200) {
          this.fleetDriverM(data.data)
          this.fleetDriver = data.data
        }
      })
    },
    handleNodeClick3(data) {
      if (data.list == null) {
        this.updTruckDriver = {
          "driverName": data.driverName,
          "driverId": data.driverID
        }
      }
    },
    //  根据车次ID查询所有关联的车辆司机数据
    findTripsTruckDriver(id) {
      this.loading1 = true
      method.selTripsTruckDriver(id).then(({data}) => {
        if (data.code == 200) {
          this.tripsTruckDriverData = data.data
          this.loading1 = false
        }
      })
    },
    //  打开车次新增司机的对话框
    openAddDriver(scop, scope) {
      this.findTripsTruckDriver(scope.trips.id)
      this.driverTripsID = scop.id
      this.zhanshiAddDriver = {
        xianluname: scop.name,
        tripsname: scope.trips.name,
        fachetime: scope.trips.departureTime
      }
      this.addDriverdialogVisible = true
    },
    //  取消车次新增司机的对话框
    addDriverhandleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {
        });
    },
    // ---------------------------------------------------------
    //  确认添加车辆
    addTruck() {
      var dx = {
        "transportTripsId": this.tripsId,
        "truckId": this.addTruckData.truckId
      }
      this.addTruckdialogVisible = false
      method.insTruck(dx).then(({data}) => {
        if (data.code == 200) {
          this.$notify({
            title: '成功',
            message: '车次添加车辆成功!',
            type: 'success'
          });
          this.pageLine()
        }
      })
    },
    //  查询所有车辆
    findTruckAll() {
      method.selTruckAll().then(({data}) => {
        if (data.code == 200) {
          this.truckAll = data.data
        }
      })
    },
    //  车队车辆树
    fleet(data) {
      for (let i = 0; i < data.length; i++) {
        this.$set(data[i], 'name', data[i].pdFleet.name)
        if (data[i].list.length > 0) {
          for (let v = 0; v < data[i].list.length; v++) {
            this.$set(data[i].list[v], 'name', data[i].list[v].licensePlate)
          }
        }
      }
    },
    handleNodeClick2(data) {
      if (data.id != null) {
        this.addTruckData = {
          "truckId": data.id,
          "truckName": data.licensePlate
        }
      }
    },
    //  查询所有车队和对应的车辆
    findFleetTruck() {
      method.selFleetTruck().then(({data}) => {
        this.fleet(data.data)
        this.fleetTruck = data.data
      })
    },
    //  打开给车次添加车辆的对话框
    openAddTruck(scop, scope) {
      this.addTruckData = {
        truckName: "",
        truckId: ""
      }
      this.tripsId = scope.trips.id
      this.findFleetTruck()
      this.zhanshiAddTruck = {
        xianluname: scop.name,
        name: scope.trips.name,
        departureTime: scope.trips.departureTime,
      }
      this.addTruckdialogVisible = true
    },
    //  取消车次添加车辆的对话框
    addTruckhandleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {
        });
    },
    //  删除车次
    delTrips(val) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {

        method.delTrips(val.trips.id).then(({data}) => {
          if (data.code == 200) {
            this.$notify({
              title: '成功',
              message: '车次删除成功!',
              type: 'success'
            })
            this.pageLine()
          }
          if (data.code == 201) {
            this.$notify({
              title: '警告',
              message: data.message,
              type: 'warning'
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    //  确认修改车次
    updTrips() {
      if (this.updTripsData.name == "" || this.updTripsData.name == null) {
        this.$notify({
          title: '警告',
          message: "请输入车次名称!",
          type: 'warning'
        })
        return
      }
      if (this.updTripsData.departureTime == "" || this.updTripsData.departureTime == null) {
        this.$notify({
          title: '警告',
          message: "请选择发车时间!",
          type: 'warning'
        })
        return
      }
      if (this.updTripsData.period == "" || this.updTripsData.period == null) {
        this.$notify({
          title: '警告',
          message: "请选择发车周期!",
          type: 'warning'
        })
        return
      }

      this.updTripsdialogVisible = false
      method.updTrips(this.updTripsData).then(({data}) => {
        if (data.code == 200) {
          this.$notify({
            title: '成功',
            message: '车次修改成功!',
            type: 'success'
          })
          this.pageLine()
        }
      })
    },
    //  关闭修改车次的对话框
    UpdTripshandleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {
        });
    },
    //  打开编辑车次的模态框
    openUpdTrips(scop, scope) {
      this.xianluname = scop.name//  *线路名称
      this.updTripsData = {
        id: scope.trips.id,
        name: scope.trips.name,
        departureTime: scope.trips.departureTime,
        period: scope.trips.period + "",
        transportLineId: scop.id,
      }
      this.updTripsdialogVisible = true
    },
    //  确认添加车次
    addtrips() {
      if (this.addTripsData.name == "" || this.addTripsData.name == null) {
        this.$notify({
          title: '警告',
          message: "请输入车次名称!",
          type: 'warning'
        })
        return
      }
      if (this.addTripsData.departureTime == "" || this.addTripsData.departureTime == null) {
        this.$notify({
          title: '警告',
          message: "请选择发车时间!",
          type: 'warning'
        })
        return
      }
      if (this.addTripsData.period == "" || this.addTripsData.period == null) {
        this.$notify({
          title: '警告',
          message: "请选择发车周期!",
          type: 'warning'
        })
        return
      }
      let dx = {
        transportLineId: this.addTransportLineId,
        departureTime: this.addTripsData.departureTime,
        name: this.addTripsData.name,
        period: this.addTripsData.period
      }

      this.adddialogVisible = false
      method.addTrips(dx).then(({data}) => {
        if (data.code == 200) {
          this.$notify({
            title: '成功',
            message: '车次添加成功!',
            type: 'success'
          })
          this.pageLine()
        }
      })
    },
    //  打开增加车次的对话框
    openaddLine(val) {
      this.addTripsData = {}
      this.xianluname = val.name//  *线路名称
      this.addTransportLineId = val.id,//  线路ID
        this.adddialogVisible = true;
    },
    //  关闭增加车次的对话框
    addhandleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {
        });
    },
    updatePolylinePath(e) {
      this.polylinePaths = e.target.getPath()
    },
    //  打开地图
    openMap(val) {
      // 初始化地图
      this.startMap = {"lng": val.startAgencyLongitude, "lat": val.startAgencyLatitude}
      this.stopMap = {"lng": val.endAgencyLongitude, "lat": val.endAgencyLatitude}
      this.map = val.name + "线路展示"
      this.dialogVisible2 = true
    },
    //  关闭修改线路的对话框
    handleClose1(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {
        });
    },
    //  打开线路修改对话框
    openUpdLine(val) {
      this.updLineData = {
        id: val.id,//  线路ID
        lineNumber: val.lineNumber,//  *线路编号
        name: val.name,//  *线路名称
        transportLineTypeId: val.tid, //  *线路类型
        startAgencyId: val.startAgencyId,//  起始地机构ID
        endAgencyId: val.endAgencyId,//  目的地机构ID
        distance: val.distance,//  *距离
        cost: val.cost,//  *成本
        estimatedTime: val.estimatedTime//  *预计时间
      }
      this.inupDictDataSelect2 = val.startAgencyName
      this.inupDictDataSelect3 = val.endAgencyName
      this.getSelectOption()
      this.dialogVisible1 = true
    },
    //  确认修改线路
    updLine() {

      if (this.updLineData.lineNumber == "" || this.updLineData.lineNumber == null) {
        this.$notify({
          title: '警告',
          message: "线路编号不能为空!",
          type: 'warning'
        })
        return
      }
      if (this.updLineData.name == "" || this.updLineData.name == null) {
        this.$notify({
          title: '警告',
          message: "线路名称不能为空!",
          type: 'warning'
        })
        return
      }
      if (this.updLineData.transportLineTypeId == "" || this.updLineData.transportLineTypeId == null) {
        this.$notify({
          title: '警告',
          message: "请选择线路类型!",
          type: 'warning'
        })
        return
      }
      if (this.updLineData.distance == "" || this.updLineData.distance == null) {
        this.$notify({
          title: '警告',
          message: "距离不能为空!",
          type: 'warning'
        })
        return
      }
      if (this.updLineData.cost == "" || this.updLineData.cost == null) {
        this.$notify({
          title: '警告',
          message: "成本不能为空!",
          type: 'warning'
        })
        return
      }
      if (this.updLineData.estimatedTime == "" || this.updLineData.estimatedTime == null) {
        this.$notify({
          title: '警告',
          message: "预计不能为空!",
          type: 'warning'
        })
        return
      }
      this.dialogVisible1 = false
      method.updLine(this.updLineData).then(({data}) => {
        if (data.code == 200) {
          this.$notify({
            title: '成功',
            message: '线路修改成功!',
            type: 'success'
          })
        }
        this.pageLine()
      })
    },
    // 下拉菜单的节点赋值
    handleNodeClick(node) {
      this.dictDataSelect = node.name;
      this.vo.orgId = node.id;
      this.$refs.selectReport.blur()
    },
    // 添加起始组织下拉框复制
    inupHandleNodeClick(node) {
      this.inupDictDataSelect = node.name;
      this.addLineData.startAgencyId = node.id;
    },
    // 添加目的地组织下拉框复制
    inupHandleNodeClick1(node) {
      this.inupDictDataSelect1 = node.name;
      this.addLineData.endAgencyId = node.id;
    },
    // 修改起始组织下拉框复制
    inupHandleNodeClick2(node) {
      this.inupDictDataSelect2 = node.name;
      this.updLineData.startAgencyId = node.id;
    },
    // 修改目的地组织下拉框复制
    inupHandleNodeClick3(node) {
      this.inupDictDataSelect3 = node.name;
      this.updLineData.endAgencyId = node.id;
    },
    // 拉取组织树的数据
    getSelectOption() {
      organizationAPI.getTreeData("").then(({data}) => {
        this.dg(data.data);
        this.list = data.data;
      })
    },
    // 组织树递归（添加id和name）
    dg(data) {
      if (data != null) {
        for (var i = 0; i < data.length; i++) {
          if (data[i].orgTreeDtoList.length > 0) {
            this.dg(data[i].orgTreeDtoList)
          }
          this.$set(data[i], 'name', data[i].pdCoreOrg.name)
          this.$set(data[i], 'id', data[i].pdCoreOrg.id)
        }
      }
    },
    //  查询所有线路数据
    pageLine() {
      this.loading = true
      method.pageLine(this.pagenum, this.pagesize, this.queryVO).then(({data}) => {

        this.tableData = data.data.list
        this.pagesum = data.data.total
        this.loading = false
      })
    },
    //  查询所有线路类型
    findLineType() {
      method.selLineType().then(({data}) => {
        if (data.code == 200) {
          this.lineTypeData = data.data
        }
      })
    },
    //  清空搜索框
    reset(formName) {
      this.$refs[formName].resetFields();
    },
    //  搜索按钮
    sousuo() {
      this.pageLine()
    },
    //  设置一页显示多少数据
    setSize(val) {

      this.pagesize = val
      this.pageLine()
    },
    //  修改总页数
    setPage(val) {

      this.pagenum = val
      this.pageLine()

    },
    //  打开添加线路的对话框
    openAddLine() {
      this.addLineData = {
        lineNumber: "",//  *线路编号
        name: "",//  *线路名称
        transportLineTypeId: "", //  *线路类型
        startAgencyId: "",//  起始地机构ID
        endAgencyId: "",//  目的地机构ID
        distance: "",//  *距离
        cost: "",//  *成本
        estimatedTime: ""//  *预计时间
      }
      this.inupDictDataSelect = ""
      this.inupDictDataSelect1 = ""
      this.getSelectOption()
      this.dialogVisible = true
    },
    //  关闭添加线路的对话框
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {
        });
    },
    //  确定添加线路
    addLine() {
      if (this.addLineData.lineNumber == "" || this.addLineData.lineNumber == null) {
        this.$notify({
          title: '警告',
          message: "线路编号不能为空!",
          type: 'warning'
        })
        return
      }
      if (this.addLineData.name == "" || this.addLineData.name == null) {
        this.$notify({
          title: '警告',
          message: "线路名称不能为空!",
          type: 'warning'
        })
        return
      }
      if (this.addLineData.transportLineTypeId == "" || this.addLineData.transportLineTypeId == null) {
        this.$notify({
          title: '警告',
          message: "请选择线路类型!",
          type: 'warning'
        })
        return
      }
      if (this.addLineData.distance == "" || this.addLineData.distance == null) {
        this.$notify({
          title: '警告',
          message: "距离不能为空!",
          type: 'warning'
        })
        return
      }
      if (this.addLineData.cost == "" || this.addLineData.cost == null) {
        this.$notify({
          title: '警告',
          message: "成本不能为空!",
          type: 'warning'
        })
        return
      }
      if (this.addLineData.estimatedTime == "" || this.addLineData.estimatedTime == null) {
        this.$notify({
          title: '警告',
          message: "预计不能为空!",
          type: 'warning'
        })
        return
      }
      this.dialogVisible = false
      method.insLine(this.addLineData).then(({data}) => {

        if (data.code == 200) {
          this.$notify({
            title: '成功',
            message: '线路添加成功!',
            type: 'success'
          })
        }
        this.pageLine()
      })
    },
    //  删除线路数据
    delLine(val) {

      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {

        method.delLine(val.id).then(({data}) => {
          if (data.code == 200) {
            this.$notify({
              title: '成功',
              message: '线路类型删除成功!',
              type: 'success'
            })
            this.pageLine()
          }
          if (data.code == 201) {
            this.$notify({
              title: '警告',
              message: data.message,
              type: 'warning'
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  },
  created() {
    this.pageLine()
    this.findLineType()
  }

}
</script>
<style>

#jigouselect {
  padding: 0;
  width: 100%;
  height: 100%;
}

.map {
  width: 100%;
  height: 300px;
}

.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
</style>
